package day12;

public class 树测试 {
    public static void main(String[] args) {
        BiTreeNode root,node,leftNode,rightNode;
        root = new BiTreeNode('A',null,null);
        node = root;
        leftNode = new BiTreeNode('B',null,null);
        node.lchild = leftNode;
        rightNode = new BiTreeNode('C',null,null);
        node.rchild = rightNode;

        node = leftNode;
        leftNode = new BiTreeNode('D',null,null);
        node.lchild = leftNode;
        rightNode = new BiTreeNode('E',null,null);
        node.rchild = rightNode;

        node = leftNode;
        rightNode = new BiTreeNode('F',null,null);
        node.rchild = rightNode;
        node.rchild.lchild = new BiTreeNode('H',null,null);

        node = root.lchild.rchild;
        node.lchild = new BiTreeNode('G',null,null);

        System.out.println("--------------递归先序遍历二叉树----------------");
        preOerder(root);
        System.out.println("\n--------------递归中序遍历二叉树----------------");
        inOerder(root);
        System.out.println("\n--------------递归后序遍历二叉树----------------");
        postOerder(root);

    }

    public static void preOerder(BiTreeNode root){
        if (root == null){
            return;
        }
        System.out.print(root.data + " ");
        preOerder(root.lchild);
        preOerder(root.rchild);
    }
    public static void inOerder(BiTreeNode root){
        if (root == null){
            return;
        }
        inOerder(root.lchild);
        System.out.print(root.data + " ");
        inOerder(root.rchild);
    }
    public static void postOerder(BiTreeNode root){
        if (root == null){
            return;
        }
        postOerder(root.lchild);
        postOerder(root.rchild);
        System.out.print(root.data + " ");
    }
}
